﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bigguy : Enemy,IDamageable
{
    public Transform PickupPoint;
    public int Power;
    public void Gethit(float damage)
    {
        health -= damage;
        if (health < 1)
        {
            health = 0;
            isDead = true;
        }
        anim.SetTrigger("hit");

    }
    public void PickUpBomb()
    {
        if (targetPoint.CompareTag("Bomb") && !hasBomb )
        {
            targetPoint.gameObject.transform.position = PickupPoint.position;

            targetPoint.SetParent(PickupPoint);

            targetPoint.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Kinematic;

            hasBomb = true;
        }
    }
    public void ThrowAway()
    {
        if (hasBomb)
        {
            targetPoint.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
            targetPoint.SetParent(transform.parent.parent);

            if (FindObjectOfType<NewBehaviourScript>().gameObject.transform.position.x - transform.position.x<0) 
            targetPoint.GetComponent<Rigidbody2D>().AddForce(new Vector2(-1, 1) * Power,ForceMode2D.Impulse );

            else
            targetPoint.GetComponent<Rigidbody2D>().AddForce(new Vector2(1, 1) * Power, ForceMode2D.Impulse);
        }
        hasBomb = false;
    }
}
